#!/usr/bin/env python
#-*- coding: utf-8 -*-
#__author__:vincentlc
#time: 16/6/4 : 09:07

'''
Find the total area covered by two rectilinear rectangles in a 2D plane.

Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.

Rectangle Area
Assume that the total area is never beyond the maximum possible value of int.
'''

class Solution(object):
    def isInSegment(self,point,seg_a,seg_b):
        if point>seg_a and point<seg_b:
            return True
        elif point<seg_a and point>seg_b:
            return True
        else:
            return False
    def overlap(self,A,B,C,D,E,F,G,H):
        h1 = max(A,E)
        h2 = max(C,G)
        h = h1 - h2

        v1 = max(B,F)
        v2 = max(D,H)
        v = v2 - v1

        if h<0 or v< 0:
            return 0
        else:
            return h*v

    def computeArea(self, A, B, C, D, E, F, G, H):
        """
        :type A: int
        :type B: int
        :type C: int
        :type D: int
        :type E: int
        :type F: int
        :type G: int
        :type H: int
        :rtype: int
        """
        # rec1_height = abs(C-A)
        # rec1_weight = abs(D-B)
        # rec2_height = abs(G-E)
        # rec2_weight = abs(H-F)
        rec1_height = C-A
        rec1_weight = D-B
        rec2_height = G-E
        rec2_weight = H-F

        OverArea = self.overlap(A,B,C,D,E,F,G,H)

        area = rec1_height*rec1_weight + rec2_height*rec2_weight - OverArea
        return area

